<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://jsptags.com/tags/navigation/pager" prefix="pg"%>
<%
	String path=request.getContextPath();
	String basePath=request.getScheme()+"://"
			+request.getServerName()+":"+request.getServerPort()
			+path+"/";
%>
<!DOCTYPE html>
<html>
<base href="<%=basePath%>">
<head>
	<title>修改密码</title>
	<meta charset="utf-8">
	<link rel="icon" href="img/logo.png" sizes="32x32">
	<link rel="stylesheet" type="text/css" href="layui/css/layui.css">
	<script type="text/javascript" src="layui/layui.js"></script>
</head>
<body>
	<div class="layui-anim layui-anim-up">
		<form class="layui-form" action="admin/updatePwd?updateFlag=true" id="form" style="margin-top: 50px;" method="post">
			<input type="hidden" name="userId" id="userId" value="${currentUser.getUserId() }">
			<input type="hidden" name="userImg" id="userImg" value="${currentUser.getUserImg() }">
			<div class="layui-form-item">
				<div class="layui-inline">
					<label class="layui-form-label">用户名</label>
					<div class="layui-input-inline">
						<input type="text" id="userName" name="userName" value="${currentUser.getUserName() }" lay-verify="userName" autocomplete="off" placeholder="请输入用户名" class="layui-input">
					</div>
				</div>
			</div>
			<div class="layui-form-item">
				<div class="layui-inline">
					<label class="layui-form-label">邮箱</label>
					<div class="layui-input-inline">
						<input type="email" id="email" name="email" value="${currentUser.getEmail() }" lay-verify="email" autocomplete="off" placeholder="请输入邮箱" class="layui-input">
					</div>
				</div>
			</div>
			<div class="layui-form-item">
				<div class="layui-inline">
					<label class="layui-form-label">新密码</label>
					<div class="layui-input-inline">
						<input type="text" id="pwd1" name="passWord" lay-verify="passWord" autocomplete="off" placeholder="请输入新密码" class="layui-input">
					</div>
				</div>
			</div>
			<div class="layui-form-item">
				<div class="layui-inline">
					<label class="layui-form-label">再次输入</label>
					<div class="layui-input-inline">
						<input type="text" id="pwd2" name="passWord2" lay-verify="passWord2" autocomplete="off" placeholder="再次输入新密码" class="layui-input">
					</div>
				</div>
			</div>
			<div class="layui-form-item">
			    <div class="layui-input-block">
			      <button type="submit" class="layui-btn" lay-submit lay-filter="demo1">保存</button>
			      <button type="reset" class="layui-btn layui-btn-primary">重置</button>
			    </div>
			</div>
		</form>
	</div>
	<c:if test="${updateFlag }">
	<script type="text/javascript">
		layui.use('layer', function() {
			var layer = layui.layer;
			layer.msg('修改成功', { icon: 1, time: 1000, shade: [0.6, '#000', true] });
		});
	</script>
	</c:if>
	<script type="text/javascript">
		layui.use('layer', function() {
			var layer = layui.layer;
			var $ = layui.jquery;
			//表单验证
			$("#form").submit(function() {
				if($("#pwd1").val()==""||$("#pwd2").val()==""){
					layer.msg('密码不能为空', { icon: 2, time: 1000, shade: [0.6, '#000', true] });
					return false;
				}else if($("#pwd1").val()!=$("#pwd2").val()){
					layer.msg('俩次输入的密码不一样', { icon: 2, time: 1000, shade: [0.6, '#000', true] });
					return false;
				}else if($("#userName").val()==""){
					layer.msg('用户名不能为空', { icon: 2, time: 1000, shade: [0.6, '#000', true] });
					return false;
				}else if($("#email").val()==""){
					layer.msg('邮箱不能为空', { icon: 2, time: 1000, shade: [0.6, '#000', true] });
					return false;
				}
				var data={userId:parseInt($("#userId").val()),userName:$("#userName").val(),passWord:$("#pwd1").val(),userImg:$("#userImg").val(),email:$("#email").val()}
				$.ajax({
		            type : "POST",
		            dataType:"json",
		            contentType: "application/json;charset=UTF-8",
		            url : "user/update",
		            async: false,
		            data : JSON.stringify(data),
		            success : function(result) {
		            	layer.msg('修改成功', { icon: 1, time: 1000, shade: [0.6, '#000', true] });
		            },
		            error : function(e){
		                console.log(e.status);
		                console.log(e.responseText);
		            }
		        });
				return true;
			});
		});
	</script>
</body>
</html>